import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";

/**
 * rateType.js - 汇率类型定义 model
 * @date: 2018-10-29
 */
import { getResponse, createPagination } from 'utils/utils';
import { queryIdpValue } from 'cpaas-front/lib/services/api';
import { queryRateType as _queryRateType, insertRateType, deleteRateType as _deleteRateType, updateRateType, queryRateTypeDetail as _queryRateTypeDetail, queryRateTypeInfo as _queryRateTypeInfo } from "../services/rateTypeService";
export default {
  namespace: 'rateType',
  state: {
    list: {},
    // 汇率类型列表
    detail: {},
    // 汇率类型引用明细
    rateMethodList: [],
    // 汇率类型方式
    tenantRateTypeList: {},
    // 租户汇率类型定义列表
    pagination: {} // 分页参数对象

  },
  effects: {
    // 查询汇率类型方式
    queryRateTypeMethod: /*#__PURE__*/_regeneratorRuntime.mark(function queryRateTypeMethod(_ref, _ref2) {
      var payload, call, put, res, rateMethodList;
      return _regeneratorRuntime.wrap(function queryRateTypeMethod$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              payload = _ref.payload;
              call = _ref2.call, put = _ref2.put;
              _context.next = 4;
              return call(queryIdpValue, payload);

            case 4:
              res = _context.sent;
              rateMethodList = getResponse(res);
              _context.next = 8;
              return put({
                type: 'updateState',
                payload: {
                  rateMethodList: rateMethodList
                }
              });

            case 8:
            case "end":
              return _context.stop();
          }
        }
      }, queryRateTypeMethod);
    }),
    // 查询平台级汇率类型
    queryRateType: /*#__PURE__*/_regeneratorRuntime.mark(function queryRateType(_ref3, _ref4) {
      var payload, call, put, res, list, pagination;
      return _regeneratorRuntime.wrap(function queryRateType$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref3.payload;
              call = _ref4.call, put = _ref4.put;
              _context2.next = 4;
              return call(_queryRateType, payload);

            case 4:
              res = _context2.sent;
              list = getResponse(res);
              pagination = createPagination(list);
              _context2.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  list: list,
                  pagination: pagination
                }
              });

            case 9:
            case "end":
              return _context2.stop();
          }
        }
      }, queryRateType);
    }),
    // 新增或更新平台级汇率类型
    saveRateType: /*#__PURE__*/_regeneratorRuntime.mark(function saveRateType(_ref5, _ref6) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function saveRateType$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              payload = _ref5.payload;
              call = _ref6.call;

              if (!payload.rateTypeId) {
                _context3.next = 8;
                break;
              }

              _context3.next = 5;
              return call(updateRateType, payload);

            case 5:
              res = _context3.sent;
              _context3.next = 11;
              break;

            case 8:
              _context3.next = 10;
              return call(insertRateType, payload);

            case 10:
              res = _context3.sent;

            case 11:
              return _context3.abrupt("return", getResponse(res));

            case 12:
            case "end":
              return _context3.stop();
          }
        }
      }, saveRateType);
    }),
    // 删除平台级汇率类型
    deleteRateType: /*#__PURE__*/_regeneratorRuntime.mark(function deleteRateType(_ref7, _ref8) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function deleteRateType$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              payload = _ref7.payload;
              call = _ref8.call;
              _context4.next = 4;
              return call(_deleteRateType, payload);

            case 4:
              res = _context4.sent;
              return _context4.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context4.stop();
          }
        }
      }, deleteRateType);
    }),
    // 查询汇率类型明细
    queryRateTypeDetail: /*#__PURE__*/_regeneratorRuntime.mark(function queryRateTypeDetail(_ref9, _ref10) {
      var payload, call, put, res, detail;
      return _regeneratorRuntime.wrap(function queryRateTypeDetail$(_context5) {
        while (1) {
          switch (_context5.prev = _context5.next) {
            case 0:
              payload = _ref9.payload;
              call = _ref10.call, put = _ref10.put;
              _context5.next = 4;
              return call(_queryRateTypeDetail, payload);

            case 4:
              res = _context5.sent;
              detail = getResponse(res);
              _context5.next = 8;
              return put({
                type: 'updateState',
                payload: {
                  detail: detail
                }
              });

            case 8:
              return _context5.abrupt("return", getResponse(res));

            case 9:
            case "end":
              return _context5.stop();
          }
        }
      }, queryRateTypeDetail);
    }),
    // 查询汇率类型信息
    queryRateTypeInfo: /*#__PURE__*/_regeneratorRuntime.mark(function queryRateTypeInfo(_ref11, _ref12) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function queryRateTypeInfo$(_context6) {
        while (1) {
          switch (_context6.prev = _context6.next) {
            case 0:
              payload = _ref11.payload;
              call = _ref12.call;
              _context6.next = 4;
              return call(_queryRateTypeInfo, payload);

            case 4:
              res = _context6.sent;
              return _context6.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context6.stop();
          }
        }
      }, queryRateTypeInfo);
    })
  },
  reducers: {
    // 批量条件查询值集头
    updateState: function updateState(state, _ref13) {
      var payload = _ref13.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    }
  }
};